<link rel="stylesheet" href="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.css" />
<div id="dplayer"></div>
<script src="https://cdn.bootcss.com/webtorrent/0.107.16/webtorrent.min.js"></script>
<script src="https://cdn.bootcss.com/dplayer/1.25.0/DPlayer.min.js"></script>
<script>
var client = new WebTorrent()


const dp = new DPlayer({
    container: document.getElementById('dplayer'),
    video: {
        url: 'magnet:?xt=urn:btih:4776E8AC74B5F8AC579F3545AAE747FB28032C46',
        type: 'customWebTorrent',
        customType: {
            customWebTorrent: function(video, player) {
                player.container.classList.add('dplayer-loading');
                const client = new WebTorrent();
                const torrentId = video.src;
                client.add(torrentId, (torrent) => {
                    const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
                    file.renderTo(
                        video,
                        {
                            autoplay: player.options.autoplay,
                        },
                        () => {
                            player.container.classList.remove('dplayer-loading');
                        }
                    );
                });
            },
        },
    },
});
</script>
